package cn.nabaixin.ui;

import cn.nabaixin.R;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;
/**
 * @author ZWH
 * 自定义的TabActivity
 */
public class SpecialTabActivity extends TabActivity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	 /**
     * 添加一个新的Tab
     * @param imgId:	图标资源Id
     * @param tabTitle:	tab的标题
     * @param cls:		tab content中的目标Activity
     * @param tag:		tab的tag
     */
	public void addNewTab(String tabTitle, int imgId, Class<?> cls, String tag){
		RelativeLayout tabIndicator = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabHost().getTabWidget(), false);
		TextView tabTitleText = (TextView)tabIndicator.findViewById(R.id.tab_title);
        tabTitleText.setText(tabTitle);
		ImageView iv = (ImageView)tabIndicator.findViewById(R.id.tab_icon);
		iv.setImageResource(imgId);
        TabSpec tabSpec = getTabHost().newTabSpec(tag)
			.setIndicator(tabIndicator)
			.setContent(new Intent(this,cls));
        getTabHost().addTab(tabSpec);
	}
    
   /* *//**
     * 添加一个新的Tab
     * @param tabTitle:	tab的标题
     * @param cls:		tab content中的目标Activity
     *//*
	public void addNewTopTab(String tabTitle, Class<?> cls, String tag){
    	
		RelativeLayout tabIndicator = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabHost().getTabWidget(), false);
        TextView tabTitleText = (TextView)tabIndicator.getChildAt(1);
        tabTitleText.setText(tabTitle);
        TabSpec tabSpec = getTabHost().newTabSpec(tag)
			.setIndicator(tabIndicator)
			.setContent(new Intent(this,cls));
        getTabHost().addTab(tabSpec);
	}
	
	*//**
     * 添加一个新的Tab
     * @param tabTitle:	tab的标题
     * @param cls:		tab content中的目标Activity
     *//*
	public void addNewTopTab(String tabTitle, Class<?> cls, String tag, AccountMessages am){
    	Intent intent = new Intent(this,cls);
    	intent.putExtra("am", am);
		RelativeLayout tabIndicator = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabHost().getTabWidget(), false);
        TextView tabTitleText = (TextView)tabIndicator.getChildAt(1);
        tabTitleText.setText(tabTitle);
        TabSpec tabSpec = getTabHost().newTabSpec(tag)
			.setIndicator(tabIndicator)
			.setContent(intent);
        getTabHost().addTab(tabSpec);
	}
	*//**
	 *添加一个新的Tab
	 * @param tabTitle:	tab的标题
	 * @param cls	:tab content中的目标Activity
	 * @param tag	:tag
	 * @param groupId	:群组Id
	 *//*
	public void addNewTopTab(String tabTitle, Class<?> cls, String tag, String groupId){
		Intent intent = new Intent(this,cls);
		intent.putExtra("gid", groupId);
		intent.putExtra("groupChatType", Constants.GMSG);
		RelativeLayout tabIndicator = (RelativeLayout) LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabHost().getTabWidget(), false);
		TextView tabTitleText = (TextView)tabIndicator.getChildAt(1);
		tabTitleText.setText(tabTitle);
		TabSpec tabSpec = getTabHost().newTabSpec(tag)
		.setIndicator(tabIndicator)
		.setContent(intent);
		getTabHost().addTab(tabSpec);
	}*/
	
	/**
	 * 设置TabWidget的高度
	 * @param height	需要设置的高度值，注意这个方法必须在addNewTab之后调用
	 */
	public void setTabWidgetHeight(int height){
		TabWidget tabWidget = getTabHost().getTabWidget();
		tabWidget.setMinimumHeight(30);
        for (int i =0; i < tabWidget.getChildCount(); i++) {  
        	tabWidget.getChildAt(i).getLayoutParams().height= height;  
        }
	}
}
